<template>
	<view class="main">
		<view class="logo">
			<image mode="widthFix" src="/static/logo.png"></image>
		</view>
		<view class="button" @click="login">
			<view class="icon">
				<image src="/static/wechat.png"></image>
			</view>
			<view class="text">微信登录</view>
		</view>
		<navigator open-type="reLaunch" url="/pages/index/index" class="back">暂不登录，返回首页</navigator>
		<view class="agreement">登录即代表您同意《用户协议》和《隐私政策》</view>
	</view>
</template>

<script>
	import wxLogin from '@/mixins/wxLogin.js'
	import common from '@/mixins/common.js'
	import {
	    mapState,
		mapMutations
	} from 'vuex';  
	export default {
		mixins:[common,wxLogin],
		data() {
			return {
				
			}
		},
		computed: {
			...mapState(['hasLogin','userInfo'])
		},
		methods: {
			login(){
				let that = this
				
				// 判断登录
				// if(!this.hasLogin){
					this.wxLogin().then(e=>{
						console.log(e)
						if(e.code == 200){
							that.showToast('登录成功');
							let page = uni.getStorageSync('return_url')
							if(page){
								uni.setStorageSync('return_url',null)
								setTimeout(function() {
									uni.reLaunch({
										url:'/'+page
									})
								}, 1000);
							}
							else{
								uni.reLaunch({
									url:'../index/index'
								})
							}
						}
						else{
							that.showToast(e.msg);
						}
					})
				// }
				// else{
				// 	// this.showToast('你好呀~ '+this.userInfo.nickName)
				// 	// 跳转到首页
				// 	uni.reLaunch({
				// 		url:'../index/index'
				// 	})
				// }
				
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #00AB8E;
}

.main{
	display: flex;
	flex-direction: column;
	align-items: center;
	height: 100vh;
	justify-content: center;
	
	.logo{
		image{
			width: 374rpx;
		}
	}
	
	.button{
		margin-top: 240rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 16rpx 100rpx;
		background: #FFFFFF;
		border-radius: 42rpx;
		.icon{
			width: 48rpx;
			height: 48rpx;
			image{
				width: 48rpx;
				height: 48rpx;
			}
		}
		.text{
			margin-left: 20rpx;
			font-size: 27rpx;
			font-weight: 400;
			color: #999999;
		}
	}
	
	.back{
		margin-top: 40rpx;
		font-size: 27rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
	}
	
	.agreement{
		position: absolute;
		text-align: center;
		width: 100%;
		left: 0;
		bottom: 55rpx;
		font-size: 27rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
	}
}

</style>
